<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>
        <Form-item label="采用的规则项" prop="forgroupid">
            <i-select v-model="formValidate.forgroupid" placeholder="请选择采用的规则项">
                <template v-for="(item,index) in fortypeArr">
                    <i-option :value="item.Url">{{item.Url}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="是否赋权" prop="rightstate">
            <i-select v-model="formValidate.rightstate" placeholder="请选择是否赋权">
                <i-option value="true">是</i-option>
                <i-option value="false">否</i-option>
            </i-select>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';
    import selectSearch from '../../components/selectSearch';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    forpeopleid: '',
                    forruleitemid: '',
                    rightstate: '',
                },
                ruleValidate: {},
                fortypeArr: [],
                //选择人员
                selectBaseInfo: {
                    "title": '选择人员',
                    "placeholder": '请输入姓名',
                    "postUrl": apiUtil.urls.userList,
                    'postType': 'user',
                },
                reqpeopleDept: '',
            }
        },

        mounted: function () {
            this.getForTypeData();
        },
        components: {
            selectSearch
        },
        methods: {
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            getForTypeData: function () {
                let that = this;

                let params = '';
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.RuleItemList, params, function (res) {
                    that.$Loading.finish();

                    that.fortypeArr = res.Msg.Arrays;
                });
            },
            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
            },
            addData: function (model) {
                let that = this;


                model.forpeopleid =this.reqpeopleDept.resultId;
                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddPeopleRule, params, function (res) {
                    that.$Loading.finish();

                    that.$Notice.open({
                        title: '通知',
                        desc: '添加成功 ',
                        duration: 0
                    });
                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
                // return ;
            },

        }
    }
</script>
